package com.toogu.mazhangmen.ui.main;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.toogu.mazhangmen.R;
import com.toogu.mazhangmen.bean.EquipmentsBean;

import java.util.List;

public class ShowFragment extends Fragment {
    private RecyclerView recyclerView;
    private MonitorWithButtonAdapter adapter;
    private List<EquipmentsBean> equipmentsBeans;

    public ShowFragment(List<EquipmentsBean> equipmentsBeanList){
        equipmentsBeans = equipmentsBeanList;
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_recycler, container, false);
        recyclerView = view.findViewById(R.id.recyclerView);
        adapter = new MonitorWithButtonAdapter(getActivity(), equipmentsBeans);
        recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 4));
        recyclerView.setAdapter(adapter);
        return view;
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
    }
    public void reStart(){
        if(adapter!=null) adapter.reStart();
    }

    public void addNewItem(EquipmentsBean equipmentsBean){
        equipmentsBeans.add(equipmentsBean);
        adapter.notifyItemChanged(equipmentsBeans.size()-1);
    }

    public List<EquipmentsBean> getEquipmentsBean2s() {
        return equipmentsBeans;
    }

    public void notifyItem(int position){
        adapter.notifyItemChanged(position);
    }
}
